package com.sx.micowell.module.message

import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.data.DataBindingConfig
import com.gyf.immersionbar.ImmersionBar
import com.miloyu.modelnet.response.SysNotice
import com.sx.micowell.BR
import com.sx.micowell.R
import com.sx.micowell.databinding.ActNewsDetailsBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyActivity
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.framework.model.MineNewsModel
import com.sx.micowell.module.web.WebViewFragment

/**
 * @Author: YY
 * @Time: 2021/8/13
 * @Describe 消息详情
 */
@Route(path = RoutePath.NEWS_DETAILS)
class NewsDetailsActivity : MyActivity<ActNewsDetailsBinding>() {

    @Autowired(name = IntentKey.DATA)
    @JvmField
    var sysNotice : SysNotice? = null

    private var viewModel: MineNewsModel? = null

    override fun initViewModel() {
        super.initViewModel()
        viewModel = getActivityScopeViewModel(MineNewsModel::class.java)
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.act_news_details, BR.viewModel, viewModel)
    }

    override fun initView() {
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(true).init()
    }

    override fun initData() {
        if (sysNotice != null) {
            binding.tvTitle.text = sysNotice!!.noticeTitle
            binding.tvTime.text = sysNotice!!.createTime
            loadRootFragment(sysNotice!!)
        }
    }


    private fun loadRootFragment(data: SysNotice) {
        supportFragmentManager.beginTransaction().add(R.id.fl_container,
            WebViewFragment.newInstance("", data.noticeContent)
        ).commit()
    }

}